package com.one.controller;

import com.one.annotation.RequestPermission;
import com.one.bean.Orders;
import com.one.service.OrderService;
import com.one.util.RequestReturn;
import com.one.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author ShiWen
 * @date 2022/1/20 9:26
 * @Version 1.0
 * @Description TODO 订单查询与物流
 */
@RestController
@Slf4j
@Api(tags = "L、订单查询与物流查询")
public class OrderQueryController {
    @Autowired
    private OrderService orderService;
    /**
     *  查询全部订单
     */
    @ApiOperation(value = "查询用户全部的订单", notes = "需要登录才能访问")
    @RequestPermission
    @GetMapping("/queryOrder")
    public RequestReturn<List<Orders>> queryAllOrder(){
        return orderService.queryAllOrder();
    }
    /**
     * @description 根据订单状态查询订单
     * @author ShiWen
     * @date 2022/1/18 16:01
     */
    @ApiImplicitParam(name = "status", value = "订单状态的编号")
    @ApiOperation(value = "根据订单的状态查询订单列表", notes = "需要传入订单状态的代码编号，0-取消1-待支付2-代发货3-待收货4-待评论-5已完成")
    @RequestPermission
    @GetMapping("/queryOrderByStatus")
    public RequestReturn<List<Orders>> queryOrderByStatus(@RequestParam("status") Integer status){
        return orderService.queryOrderByStatus(status);
    }
    /**
     *  查询订单详细信息
     */
    @ApiImplicitParam(name = "orderId", value = "订单的id")
    @ApiOperation(value = "查询单个订单的详细信息", notes = "需要传入订单的id，根据id进行查询")
    @RequestPermission
    @GetMapping("/queryOrderById")
    public RequestReturn<OrderVo> queryById( @RequestParam Integer orderId){
        return orderService.queryById(orderId);
    }

    /**
     *  快递下单
     */
    @ApiImplicitParam(name = "orderNo", value = "订单的编号")
    @ApiOperation(value = "订单发货", notes = "需要传入订单的编号")
    @PostMapping("/orderExpress")
    public RequestReturn<String> orderExpress(String orderNo){
        return orderService.orderExpress(orderNo);
    }
    /**
     * @description 快递查询
     * @author ShiWen
     * @date 2022/1/19 8:39
     */
    @ApiImplicitParam(name = "orderId", value = "订单的id")
    @ApiOperation(value = "查询物流状态", notes = "需要传入快递单号，订单编号可以省略")
    @PostMapping("/selectExpress")
    public RequestReturn<Map<String,Object>> selectExpress(@RequestParam String LogisticCode, String orderNo){
        return orderService.selectExpress(LogisticCode,orderNo);
    }
}
